package com.leetCode.easy;

/**
 * 分糖果
 */
public class PointsOfCandy {

    public static void main(String[] args) {
        int[] ints = distributeCandies(7, 4);
        for (int anInt : ints) {
            System.out.println("anInt = " + anInt);
        }
    }

    public static int[] distributeCandies(int candies, int num_people) {
        int[] nums = new int[num_people];
        int t = 0;
        while (num_people > 0) {
            for (int i = 0; i < nums.length; i++) {
                t++;
                nums[i] = nums[i] + t;
                num_people = num_people - t;
                if (num_people < t && i < nums.length - 1) {
                    nums[i + 1] = nums[i + 1] + num_people;
                    return nums;
                }else if (t > num_people && i == nums.length - 1){
                    nums[0] = nums[0] + num_people;
                    return nums;
                }
            }
        }
        return nums;
    }
}
